﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Xeno.Core;
namespace XenoStudio
{
    public partial class ShadeyNodeControl : Control{

        [Description("Image override"),Category("NodeControl"),Browsable(true)]
        public Image UseImage { get; set; }

        public XenoEffectNode Node { get; set; }

        public Image GetImage(string name)
        {
            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream file =
                thisExe.GetManifestResourceStream("XenoStudio.Resource." + name);
            if (file == null)
            {
                return null;
            }
            return Image.FromStream(file);
        }
        public ShadeyNodeControl()
        {
            InitializeComponent();
        //    if (UseImage == null)
      //      {
                UseImage = GetImage("ShadeyBGSkin.png");
    //        }
        }

        private void ShadeyNodeControl_Paint(object sender, PaintEventArgs e)
        {
            var g = e.Graphics;

            if (UseImage != null)
            {
                
                g.DrawImage(UseImage, new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height));


            }

            if (Node != null)
            {
                g.DrawString(Node.NodeType.ToString() + ":" + Node.ID, SystemFonts.SmallCaptionFont, Brushes.White, new PointF(4, 4));

            }

        }
        private int DragX = 0, DragY = 0;
        private bool Drag = false;
        private void ShadeyNodeControl_MouseDown(object sender, MouseEventArgs e)
        {
            Drag = true;
            DragX = e.X;
            DragY = e.Y;
            NardoVinchi.ActiveNode = this;
        }

        private void ShadeyNodeControl_MouseUp(object sender, MouseEventArgs e)
        {
            Drag = false;
        }

        private void ShadeyNodeControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (!Drag) return;
        int nx,ny;
            nx = Left+(e.X-DragX);
            ny = Top+(e.Y-DragY);
            Node.UIPos = new OpenTK.Vector2(nx, ny);

            if (Left != nx || Top != ny)
            {
                Left = nx;
                Top = ny;
                var sc = Parent as ShadeyNodeAreaControl;
                sc.Invalidate();
                
            }


        }
    }
}
